from django.db import models
from project_budget.utils.baseModels import BaseModel
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import Group

from datetime import datetime


#  人员=》角色=》权限组  或  单个权限
# 人员管理
# ForeignKey    ManyToManyField

class People(AbstractUser):
    name = models.CharField('姓名', max_length=50, null=True)
    Role = models.ManyToManyField('Position', verbose_name='职位', null=True)
    phone = models.CharField('手机号', max_length=11, null=True)
    peopleState = models.CharField('员工状态', max_length=50, null=True)
    entryTime = models.CharField('入职时间', max_length=50, null=True)

    class Meta:
        db_table = 'People'


# 部门信息表
class Department(BaseModel):
    name = models.CharField('部门名称', max_length=100)
    state = models.BooleanField('部门状态', default=False)
    principal = models.CharField('部门负责人', max_length=64, null=True)
    coding = models.CharField('部门编码', max_length=128)
    principalPhone = models.CharField('手机号', max_length=11)
    # people = models.ManyToManyField(to='People')
    materialBudget = models.IntegerField('材料预算', null=True)


# 职位表
class Position(BaseModel):
    jobName = models.CharField('职位名称', max_length=64)
    department = models.ForeignKey(to='Department', on_delete=models.CASCADE, null=True)
    groups = models.ManyToManyField(to=Group, verbose_name="权限组", null=True)
    job = models.CharField('对应职位', max_length=64, null=True)
    rank = models.CharField('对应职级', max_length=64, null=True)
    peopleNum = models.IntegerField('编制人数', null=True)
    authoritys = models.ManyToManyField(to='Authority')

    class Meta:
        db_table = 'Position'


class Authority(BaseModel):
    url = models.CharField("路由", max_length=33)
    title = models.CharField("路由名", max_length=50)

    class Meta:
        db_table = 'Authority'


# 工程项目
class Project(BaseModel):
    name = models.CharField('工程名称', max_length=50)
    site = models.CharField('工程地点', max_length=50)
    project_type = models.CharField('工程类型', max_length=50)
    money = models.CharField('工程预算金额', max_length=50)
    principal = models.CharField('工程负责人', max_length=50)


# 材料
class ProjectMaterials(BaseModel):
    name = models.CharField('商品名称', max_length=50)
    price = models.CharField('商品价格', max_length=50)
    project_type = models.CharField('工程类型', max_length=50)
    money = models.CharField('工程预算金额', max_length=50)
    principal = models.CharField('工程负责人', max_length=50)
    materialsClassify = models.ForeignKey(to='MaterialsClassify', on_delete=models.CASCADE)


# 材料分类表
class MaterialsClassify(BaseModel):
    name = models.CharField('分类名称', max_length=64)
    level = models.CharField('分类等级', max_length=6)
    pid = models.CharField('父级分类', max_length=32)


# 工程列表
class ProjectList(BaseModel):
    store = models.ManyToManyField(to='Store', verbose_name='仓库', null=True, blank=True)
    template_id = models.CharField("模板id", max_length=5)
    people_name = models.CharField('填表人', max_length=64)
    project = models.ForeignKey(to='Project', on_delete=models.CASCADE)  # 对应项目
    create_time = models.DateTimeField("创建时间", auto_now=True)


# 库存管理
class Store(BaseModel):
    name = models.CharField('仓库名称', max_length=64)
    store_status = models.BooleanField('库存状态', default=True)
    create_time = models.DateTimeField("创建时间", auto_now_add=True)
    all_price = models.IntegerField("总价格", max_length=15, default=0)
    all_num = models.IntegerField("总数量", max_length=15, default=0)


# 库存对应的材料
class Store_Materials(BaseModel):
    # 一对多，

    name = models.CharField('材料名称', max_length=64)
    materials_id = models.CharField("材料id", max_length=32)
    materials_num = models.CharField("入库总量", max_length=32)
    materials_status = models.BooleanField("材料状态", default=True)
    materials_price = models.CharField("总价格", max_length=33)
    materials_type = models.CharField("材料类别", max_length=50)
    create_time = models.DateTimeField('创建时间', auto_now_add=True)
    store = models.ForeignKey(to=Store, on_delete=models.CASCADE)


# 材料明细
class GoodsDetail(BaseModel):
    name = models.CharField('商品名称', max_length=64)
    goodsType = models.CharField('商品类别', max_length=64)
    storeNum = models.IntegerField('入库数量', null=True)
    goodsPrice = models.CharField('商品单价', max_length=64)
    goodsId = models.CharField('商品编码', max_length=128)
    particulars = models.CharField('备注', max_length=256)
    Store = models.ForeignKey(to='Store', on_delete=models.CASCADE)


# 模板管理
class Template(BaseModel):
    name = models.CharField('模板名称', max_length=64)
    explain = models.CharField('模板说明', max_length=256, null=True, blank=True)
    temp_status = models.BooleanField('模板状态', default=True)
    file = models.TextField('模板文件', max_length=5000)
    file_title = models.CharField(max_length=5000, null=True)
    file_excel = models.CharField(max_length=5000, null=True)


# 日志
class Log(BaseModel):
    name = models.CharField('操作人员', max_length=64)
    belongToModel = models.CharField('所属模块', max_length=64, null=True)
    operateObj = models.CharField('操作对象', max_length=128)
    operateType = models.CharField('操作类型', max_length=64, null=True)
    update_time = models.DateTimeField(auto_now_add=True)  # 操作时间

    class Meta:
        db_table = "log"


# 菜单表
class Menus(models.Model):
    title = models.CharField("菜单名", max_length=50)
    urls = models.CharField("路由", max_length=50)

    class Meta:
        db_table = "menus"


# 入库信息
class StorageMessage(models.Model):
    store_name = models.CharField('仓库名称', max_length=255)
    materials_name = models.CharField('材料名称', max_length=255)
    store_coome_num = models.IntegerField('入库数量')
    materials_price = models.IntegerField('材料单价')
    materials_code = models.CharField('材料编码', max_length=255, null=True, blank=True)
    store = models.ForeignKey(to='Store', on_delete=models.CASCADE)
    update_time = models.DateTimeField(auto_now_add=True, blank=True, null=True)

    class Meta:
        db_table = "StorageMessage"


# 出库信息
class StorageRemoval(models.Model):
    project_name = models.CharField('工程名称', max_length=255)
    store_name = models.CharField('库名称', max_length=255, null=True)
    materials_name = models.CharField('材料名称', max_length=255)
    store_removal_num = models.IntegerField('出库数量')
    all_price = models.IntegerField('出库总金额', null=True)

    operator = models.CharField('操作员', max_length=255)
    remark = models.CharField('备注', max_length=255)
    store = models.ForeignKey(to='Store', on_delete=models.CASCADE)
    materials_grade = models.CharField('材料等级', max_length=255)
    update_time = models.DateTimeField('出库时间', auto_now_add=True, blank=True, null=True)

    class Meta:
        db_table = "StorageRemoval"






















